# basic phone format validator
class PhoneValidator < ActiveModel::EachValidator
  REGEXP = /^1\d{10}$/
  def validate_each(record, attribute, value)
    record.errors.add attribute, (options[:message] || I18n.t('rails_validation.phone.invalid')) unless value =~ REGEXP
  end
end
module ActiveModel
  module Validations
    module HelperMethods
      def validates_phone_of(*attr_names)
        validates_with PhoneValidator, _merge_attributes(attr_names)
      end
    end
  end
end
